package sbt.selenium.applogic2;

import sbt.selenium.applogic.FilmHelper;
import sbt.selenium.model.Film;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

  public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }
  
  @Override
  public void createFilmOK(Film film) {
	  pages.internalPage.clickAddNewFilmLink().ensurePageLoaded()
	  .setFilmTitleField(film.getTitle())
	  .setFilmYearField(film.getYear())
	  .clickSubmitButton();
	  pages.addNewFilmPage.ensureFilmAdded();

  }
  
  @Override
  public void createFilmNO(Film film) {
	  pages.internalPage.clickAddNewFilmLink().ensurePageLoaded();
	  pages.addNewFilmPage.ensureErrorsOnPage();
	  pages.addNewFilmPage.setFilmTitleField(film.getTitle())
	  .setFilmYearField(film.getYear())
	  .clickSubmitButton();
	  pages.addNewFilmPage.ensureErrorsOnPage();

  }

  @Override
  public void deleteFilm(String title) {
	  searchFilmOK(title);
	  pages.internalPage.clickSearchedFilm(title);
	  pages.filmViewPage.clickDeleteLink();
	  pages.internalPage.ensurePageLoaded();
  }

  @Override
  public void searchFilmOK(String title) {
	  pages.internalPage.ensurePageLoaded()
	  .setFilmTitleField(title)
	  .enterSearchField().ensureFilmSearched(title);
  }
  
  @Override
  public void searchFilmNO(String title) {
	  pages.internalPage.ensurePageLoaded()
	  .setFilmTitleField(title)
	  .enterSearchField().ensureFilmNotSearched();
  }

}
